{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from pandas import Series, DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Plate ID', 'Registration State', 'Issue Date', 'Vehicle Make',\n",
       "       'Street Name', 'Date First Observed', 'Vehicle Color'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filename = '../data/nyc-parking-violations-2020.csv'\n",
    "\n",
    "df = pd.read_csv(filename,\n",
    "                usecols=['Date First Observed', 'Plate ID', 'Registration State',\n",
    "                        'Issue Date', 'Vehicle Make', 'Street Name', 'Vehicle Color'])\n",
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set the index to the \"Issue Date\" column\n",
    "df = df.set_index('Issue Date')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Vehicle Make\n",
       "TOYOT    3829\n",
       "HONDA    3593\n",
       "FORD     3164\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# what three vehicle makes were most likely to be ticketed on January 2nd?\n",
    "df.loc['01/02/2020 12:00:00 AM', 'Vehicle Make'].value_counts().head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Street Name\n",
       "WB CONDUIT BLVD @ LI    1068\n",
       "SB WEST ST @ LEROY S     335\n",
       "EB HORACE HARDING EX     273\n",
       "EB QUEENS BLVD @ 82N     245\n",
       "WB ATLANTIC AVE @ CL     229\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# On what five streets were cars most likely to be ticketed on June 1st, 2020?\n",
    "df.loc['06/01/2020 12:00:00 AM', 'Street Name'].value_counts().head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change the index to be \"Vehicle Color\"\n",
    "df = df.reset_index().set_index('Vehicle Color')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Vehicle Make\n",
       "HONDA    39353\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# What was the most common make of ticketed cars that were either blue or red?\n",
    "df.loc[['BLUE', 'RED'], 'Vehicle Make'].value_counts().head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
